﻿var StartLayer = cc.Layer.extend({
    ctor: function () {
        this._super();

        var size = cc.winSize;

        var helloLabel = new cc.LabelTTF("Hello World", "", 38);
        helloLabel.x = size.width / 2;
        helloLabel.y = size.height / 2;
        this.addChild(helloLabel);
        this.bgSprite = new cc.Sprite(res.BackGround_png);
        this.bgSprite.attr({
            x: size.width / 2,
            y: size.height / 2,
        });
        this.addChild(this.bgSprite, 0);
        var startItem = new cc.MenuItemImage(
             res.Start_N_png,
             res.Start_S_png,
             function () {
                 cc.log("Menu is clicked!");
                 cc.director.runScene(new PlayScene());
             }, this);
        startItem.attr({
            x: size.width / 2,
            y: size.height / 2,
            anchorX: 0.5,
            anchorY: 0.5
        });

        var menu = new cc.Menu(startItem);
        menu.x = 0;
        menu.y = 0;
        this.addChild(menu, 1);
        return true;
    }
});

var MenuLayer = cc.Layer.extend({
    ctor: function () {
        this._super();
        var size = cc.director.getWinSize();
        var item = new cc.MenuItemImage(
                "res/start_N.png",
                "res/start_S.png",
                function () {
                    cc.director.runScene(new PlayScene());
                }, this
            );
        item.attr({
            x: size.width / 2,
            y: size.height / 2,
            anchorX: 0.5,
            anchorY: 0.5
        });
        var menu = new cc.Menu(item);
        menu.x = 0;
        menu.y = 0;
        this.addChild(menu);
    }
});

var StartScene = cc.Scene.extend({
    onEnter: function () {
        this._super();
        //    var layer = new StartLayer();
        //    this.addChild(layer);
        var size = cc.director.getWinSize();
        var bg = new cc.Sprite("res/background.png");
        bg.x = size.width / 2;
        bg.y = size.height / 2;
        this.addChild(bg);

        var menuLayer = new MenuLayer();
        this.addChild(menuLayer);
    }
});